﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wjtour.Common;
using Hjp.FrameWork.Common;

namespace Wjtour.Web.Front
{
    public partial class complaints : BasePage
    {
        protected TextBox name;
        protected TextBox mobile;
        protected TextBox email;
        protected TextBox subject;
        protected TextBox content;
        protected TextBox code;
        protected Button submit;

        private int page = 1;
        protected PaginationData<Wjtour.Domain.suggestion> data = new PaginationData<Wjtour.Domain.suggestion>();
        private Wjtour.BLL.suggestion_bll _bll = new BLL.suggestion_bll();

        protected void Page_Load(object sender, EventArgs e)
        {
            page = Utils.StrToInt(Request["page"], 1);
            submit.Click += submit_Click;
            bindList();
        }

        void submit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(name.Text))
            {
                Utils.Alert(this.Page, "姓名不能为空！");
                return;
            }
            if (string.IsNullOrWhiteSpace(subject.Text))
            {
                Utils.Alert(this.Page, "主题不能为空！");
                return;
            }
            if (string.IsNullOrWhiteSpace(content.Text))
            {
                Utils.Alert(this.Page, "内容不能为空！");
                return;
            }
            if (string.IsNullOrWhiteSpace(code.Text))
            {
                Utils.Alert(this.Page, "验证码不能为空！");
                return;
            }
            if (code.Text.ToUpper() != Session["CheckCode"].ToString())
            {
                Utils.Alert(this.Page, "验证码输入不正确！");
                return;
            }
            Wjtour.BLL.suggestion_bll _suggestion_bll = new BLL.suggestion_bll();
            Wjtour.Domain.suggestion suggestion = new Domain.suggestion();
            suggestion.addtime = DateTime.Now;
            suggestion.content = content.Text;
            suggestion.email = email.Text;
            suggestion.name = name.Text;
            suggestion.phone = mobile.Text;
            suggestion.title = subject.Text;
            suggestion.isaudit = 1;

            bool b = _suggestion_bll.Save(suggestion);
            if (b)
            {
                Utils.Alert(this.Page, "保存成功，您的投诉审核后才能被看到！");
                Utils.Redirect(this, "complaints.aspx", false);
            }
        }

        void bindList()
        {
            data = _bll.GetAuditList(null, page - 1, 6, 2);
            PagnationHtml = GetPageHtml("complaints.aspx", page, data.Pager.TotalPages);
        }
    }
}
